<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>第三章：函数代码代理测试--模拟错误</title>
    </head>
    <body>
        <div id="test1" style="cursor:hand;">
            test1,click me!
        </div>
        <div id="test2" style="cursor:hand;">
            test2,click me!
        </div>
        <div id="test3" style="cursor:hand;">
            test3,click me!
        </div>
        <script type="text/javascript">
            function addEvent(elem, type, fn){
                if (elem.addEventListener)// FF
                    elem.addEventListener(type, fn, false);
                else 
                    if (elem.attachEvent)// IE
                        elem.attachEvent("on" + type, fn);
            }
            
            var doms = document.getElementsByTagName("div");
            var length = doms.length;
            for (var i = 0; i < length; i++) {
                var m = "you click test" + (i + 1);
                var callback = function(){
                    alert(m);
                };
                addEvent(doms[i], 'click', callback);
            }
        </script>
    </body>
